import os
import time

def delete_old_logs(log_dir, days_to_keep):
    """
    删除指定目录下超过指定天数的日志文件。

    :param log_dir: 日志文件所在目录
    :param days_to_keep: 保留天数
    """
    current_time = time.time()
    for file in os.listdir(log_dir):
        if file.endswith('.log'):
            file_path = os.path.join(log_dir, file)
            file_mtime = os.path.getmtime(file_path)
            days_alive = (current_time - file_mtime) / (24 * 60 * 60)
            if days_alive > days_to_keep:
                os.remove(file_path)
                print(f"已删除过期日志文件：{file_path}")

# log_dir = '../outFiles/logs'
# days_to_keep = 1
# delete_old_logs(log_dir, days_to_keep)
